library(tidyverse)
## ── Attaching packages ───────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1     ✓ purrr   0.3.3
## ✓ tibble  2.1.3     ✓ dplyr   0.8.4
## ✓ tidyr   1.0.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.4.0
## ── Conflicts ──────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(DT)
SNPs<- read.table("23andMe_complete.txt", header = TRUE, sep = "\t")

Exercise 1

p<-ggplot(data = SNPs) +
  geom_bar(mapping = aes(x = chromosome), fill = '#66CCFF')
p + ggtitle("Total SNPs for each chromosome") + 
  xlab("Chromosome") +
  ylab("Total number of SNPs")

Exercise 2

mycolor <-c("AA"='#FF9999', "AC"='#FF9999', "AG"='#FF9999', "AT"='#FF9999', "CC"='#FF9999', "CG"='#FF9999', "CT"='#FF9999', "GG"='#FF9999', "GT"='#FF9999', "TT"='#FF9999', "A"='#9999FF', "C"='#9999FF', "G"='#9999FF', "T"='#9999FF', "I"='#66CC99', "II"='#66CC99', "DI"='#66CC99', "DD"='#66CC99', "D"='#66CC99', "--"='#FFFF99')
p<-ggplot(data = SNPs) + 
  geom_bar(mapping = aes(x = chromosome, fill = genotype))
p + ggtitle("Total SNPs for each chromosome") +
  xlab("Chromosome") +
  ylab("Total number of SNPs") +
  theme(axis.title.x = element_text(face="bold")) +
  theme(axis.title.y = element_text(face="bold")) +
  scale_fill_manual(values=c(mycolor))

Exercise 3

Genotype counts per chromosome

Genotype counts per chromosome

Exercise 4

p<-ggplot(data = SNPs) + 
  geom_bar(mapping = aes(x = chromosome, fill = genotype), position = "dodge") +
  facet_wrap(~genotype, ncol = 2)
p + ggtitle("Total SNPs for each genotype") +
  xlab("Genotype") +
  ylab("Total number of SNPs") +
  theme(axis.title.x = element_text(face="bold")) +
  theme(axis.title.y = element_text(face="bold")) 

Exercise 5

p<-ggplot(data = SNPs) + 
  geom_bar(mapping = aes(x = chromosome, fill = genotype), position = "dodge") +
  facet_wrap(~genotype, ncol = 2)
ggplotly(p)

Exercise 6

Ytable <-subset(SNPs, chromosome == 'Y')
datatable(Ytable)
## Warning in instance$preRenderHook(instance): It seems your data is too big
## for client-side DataTables. You may consider server-side processing: https://
## rstudio.github.io/DT/server.html